<template>

<div class="container" style="width:94%;padding:0;margin-top:80px" >
  <div class="row">
     <div class="col-xs-0 col-sm-0 col-md-3" style="margin-left:40px">
            <div class="col-md-12">
              <div class="authorinfo">
                 <img class="background" src="../../assets/350.jpg" alt="" />
                  <img :src="bloginfo.avatar" class="avatar" alt="" />
                  <p class="name"><i class="el-icon-user-solid"></i> {{bloginfo.nickname}}</p>
                   <p class="email"><el-button type="info" icon="el-icon-message" circle size="mini"></el-button> &nbsp;{{bloginfo.email}}</p>
                  <div class="line"></div>

                  <ul class="authorcount">
                    <li>
                      <p>{{authorinfo.lookCount}}</p>
                      <p>阅读</p>
                    </li>
                    <li>
                      <p>{{authorinfo.supportCount}}</p>
                      <p>获赞</p>
                    </li>
                    <li>
                      <p>{{authorinfo.commentCount}}</p>
                      <p>评论</p>
                    </li>
                    <li>
                      <p>{{authorinfo.collectionCount}}</p>
                      <p>收藏</p>
                    </li>
                  </ul>
              </div>


            </div>

      <div class="col-md-12" >
        <div class="recommenddd">  
            <span>热门文章</span>
             <hr> 
            <ul class="contenttt" style="margin-left:20px;padding:0">
                <li  v-for="hot in hotList" :key="hot.id">
                     <img
                        :src="hot.cover"
                        class="img-responsive"
                        :alt="hot.title"
                      >
                    <p class="text">{{hot.title}}</p>
                    <p class="info">
                        <b class="glyphicon glyphicon-star-empty" style="color: orange;"> {{hot.collectionCount}}</b>
                        <b class="glyphicon glyphicon-thumbs-up" style="color: red;"> {{hot.supportCount}}</b>
                        <b class="glyphicon glyphicon-comment"> {{hot.commentCount}}</b>
                    </p>
                </li>
               
            </ul>
        </div>
        
          <div class="recommenddd">   
            <span>作者排行榜</span>
             <hr> 
            <ul class="contenttt" style="margin-left:20px;padding:0">
                <li  v-for="author in hotAuthor" :key="author.id">
                     <img
                        :src="author.avatar"
                        class="img-responsive"
                        style="width:90px;border-radius:50%;"
                      >
                    <p class="text"><i class="el-icon-user-solid"></i> {{author.nickname}}</p>
                    <p class="info">
                        <b style="font-size:13px">总获赞 {{author.count}}</b>
               
             
                    </p>
                    <hr>
                </li>
               
            </ul>
        </div>

        

        </div>

 

      </div>
    <div class="col-xs-12 col-sm-12 col-md-8" style="margin-left:-20px">
        <div class="textt">
          <p class="texttitle">{{bloginfo.title}}</p>
          <div class="textinfoo">
            <img  src="https://csdnimg.cn/release/blogv2/dist/pc/img/original.png" alt="">
            <p><i class="el-icon-s-custom"></i> {{bloginfo.nickname}}</p>
            <p><i class="el-icon-date"></i> {{bloginfo.created}}</p>
            <p><i class="el-icon-thumb"></i> {{bloginfo.supportCount}}</p>
            <p><i class="el-icon-view"></i> {{bloginfo.lookCount}}</p>
            <p><i class="el-icon-star-off"></i> {{bloginfo.collectionCount}}</p>
          </div>
          <div v-html="bloginfo.content" class="textcontent"></div> 

          <div class="operation"> 
            <p :class="{changeStyle:changeSelectStyle == 1}" @click="support(1)"><i class="el-icon-thumb" ></i> {{bloginfo.supportCount}} {{supportstatus}}</p>
            <p :class="{changeStyle2:changeSelectStyle2 == 1}" @click="collection(1)"><i class="el-icon-star-off"></i> {{bloginfo.collectionCount}} {{collectionstatus}}</p>
            <p><i class="el-icon-share"></i> 分享</p>
            <p><i class="el-icon-bank-card"></i> 打赏</p>
            

          </div>

        </div>

        
          <div class="comment">
            
            <div class="commentcontent"></div>
              <img :src="userinfo.avatar"
                 width="40"
                 height="40"
                 style="border-radius:50%" alt="">
              <el-form  label-width="60px" style="height:50px">
              <el-form-item>
              <el-input v-model="commentinfo.commentContent" placeholder="评论 '就这' 可以鼓励作者" style="margin-left:-10px;width:90%"></el-input>
              </el-form-item>
              <el-form-item>
              <el-button type="primary" @click="comment()" class="tbutton">评论</el-button>
              </el-form-item>
              </el-form>
              
               <div class="commentlist" v-for="comment in commentlist" :key="comment.id">
                <img :src="comment.avatar"
                 width="40"
                 height="40"
                 style="border-radius:50%" alt="">
                  <p class="commentname">{{comment.nickname}}: </p>
                  <p class="commenttext"> &nbsp;&nbsp;{{comment.commentContent}}</p>
                  <p style="font-size:13px;margin-top:8px;margin-left:15px"> &nbsp;&nbsp;{{comment.commentCreated}}</p>
                  <p style="font-size:14px;color:blue;margin-top:8px;margin-left:10px; cursor:pointer;" @click="deletecomment(comment.id)" v-if="comment.pid!='0'">回复{{comment.pname}}</p>
                  <p style="font-size:14px;color:blue;margin-top:8px;margin-left:10px; cursor:pointer;" @click="commentback(comment.id)">回复</p>
                  <p style="font-size:14px;color:blue;margin-top:8px;margin-left:10px; cursor:pointer;" @click="deletecomment(comment.id)" v-if="comment.consumerId===userinfo.id">删除</p>
                  <!-- <p :class="{changeStyle:commentSupportStyle == comment.id}"  @click="commentsupport(comment.id)" style="cursor:pointer;"><i class="el-icon-thumb" ></i> {{commentinfo.likeCount}} </p> -->

             <el-form  label-width="60px" style="height:50px" :class="{commentStyle:commentSelectStyle == comment.id}" class="com2">
              <el-form-item>
              <el-input v-model="commentContent" style="margin-left:-10px;width:90%"></el-input>
              </el-form-item>
              <el-form-item>
              <el-button size="mini" type="primary" @click="commentback2(comment.id,comment.nickname)" class="tbutton" style="right:30px;z-index:10">回复</el-button>
              <el-button size="mini" type="primary" @click="quxiao()" class="tbutton" style="right:-30px" >取消</el-button>
              </el-form-item>
              </el-form>

              
               </div>
          </div>

          
         
     </div>
  </div>
</div>
</template>

<script>
import index from '@/api/index'
import blog from '@/api/blog'
import cookie from 'js-cookie';
export default {

    data(){
      return{
      changeSelectStyle:'',
      changeSelectStyle2:'',
      commentSelectStyle:'1',
      commentSupportStyle:'',
      hotList:[],
      hotAuthor:[],
      bloginfo:{},
      authorinfo:{},
      userinfo:{},
      supportinfo:{},
      supportstatus:'点赞',
      collectionstatus:'收藏',
      commentlist:[],
      commentinfo:{
        commentContent:'',

      },
      commentContent:'',
      commentsupportinfo:{}
      }
    },
    created(){
      this.getUserInfo()
      this.getFrontBlogInfo()
      this.getHotBlog()
      this.getHotAuthor() 
      this.getCommentlist()
    },
   mounted:function(){
         this.addlook()
    },
    methods:{
      commentback(id){
        this.commentSelectStyle=id
      },
      commentback2(id,nickname){
        this.commentinfo.pid=id
        this.commentinfo.pname=nickname
        this.commentinfo.commentContent=this.commentContent
        this.comment()
        this.commentContent=''
        this.quxiao()
      },
      quxiao(){
          this.commentSelectStyle='1'
      },
      addlook(){
        blog.addlook(this.$route.params.id)   
      },
      getHotAuthor(){
      
      blog.getHotAuthor()
      .then(response => {
        this.hotAuthor = response.data.data.hotAuthor
       
      })
    },

    getCommentlist(){
      blog.getCommentlist(this.$route.params.id)
      .then(response => {
        this.commentlist = response.data.data.comments
      })
    },
     getHotBlog(){
      index.getHotData()
        .then(response => {
          this.hotList = response.data.data.hot
         
        })
    },
    getFrontBlogInfo(){
      blog.getFrontBlogInfo(this.$route.params.id)
      .then(response => {
        this.bloginfo = response.data.data.blogWebVo
        this.getAuthorCount()
      })
     
    },
    getAuthorCount(){
      blog.getAuthorCount(this.bloginfo.author)
      .then(response => {
        this.authorinfo = response.data.data.authorInfo
      })
    },
    getUserInfo(){
      
        var userStr = cookie.get('ucenter')
        if(userStr) {
        this.userinfo = JSON.parse(userStr)
        this.supportinfo.consumerId=this.userinfo.id
        this.supportinfo.blogId=this.$route.params.id
    }else{
      this.supportinfo.consumerId=''
    }
        blog.supportor(this.supportinfo)
        .then(response => {
            if(response.data.data.exist==='true'){
              this.changeSelectStyle=1
              this.supportstatus='已赞'
            }
            blog.supportadd(this.supportinfo.blogId)
        })

         blog.collectionor(this.supportinfo)
        .then(response => {
            if(response.data.data.exist==='true'){
              this.changeSelectStyle2=1
              this.collectionstatus='已收藏'
            }
            blog.collectionUpdate(this.supportinfo.blogId)
        })

    },
    support(index){

      if(this.supportinfo.consumerId==''){
       window.location.href = '/login'

      }else{
         if(this.changeSelectStyle == index){
         
        blog.delsupport(this.supportinfo)
        .then(response => {
          this.changeSelectStyle=0
          blog.supportadd(this.supportinfo.blogId)
          .then(response =>{
          this.getFrontBlogInfo()
          this.supportstatus='点赞'
          })
          
      })
      }else{
      
        blog.blogsupport(this.supportinfo)
        .then(response => {
          this.changeSelectStyle = index;
          blog.supportadd(this.supportinfo.blogId)
          .then(response =>{
          this.getFrontBlogInfo()
          this.supportstatus='已赞'
          })
          
          
      })
      }
      }
     
    },
    //  commentsupport(index){
    //   this.getCommentInfo(index)
    //   if(this.supportinfo.consumerId==''){
    //    window.location.href = '/login'

    //   }else{
    //      if(this.commentSupportStyle == index){
    //     this.commentsupportinfo.consumerId=this.supportinfo.consumerId
    //      this.commentsupportinfo.commentId=index
    //     blog.delcommentsupport(this.commentsupportinfo)
    //     .then(response => {
    //       this.commentSupportStyle=0
    //       blog.updateSupportCount(index)
    //       .then(response =>{
    //       })
          
    //   })
    //   }else{
      
    //     blog.commentsupport(this.commentsupportinfo)
    //     .then(response => {
    //       this.commentSupportStyle = index;
    //        blog.updateSupportCount(index)
    //       .then(response =>{

    //       })
          
          
    //   })
    //   }
    //   }
     
    // },
    collection(index){

      if(this.supportinfo.consumerId==''){
       window.location.href = '/login'

      }else{
         if(this.changeSelectStyle2 == index){
         
        blog.delcollection(this.supportinfo)
        .then(response => {
          this.changeSelectStyle2=0
          blog.collectionUpdate(this.supportinfo.blogId)
          this.collectionstatus='收藏'
          this.getFrontBlogInfo()
      })

       


      }else{
      
        blog.blogcollection(this.supportinfo)
        .then(response => {
          this.changeSelectStyle2 = index;
          blog.collectionUpdate(this.supportinfo.blogId)
          this.collectionstatus='已收藏'
          this.getFrontBlogInfo()
      })
      }
      }
     
    },

    comment(){
      this.commentinfo.consumerId = this.supportinfo.consumerId
      this.commentinfo.blogId =  this.supportinfo.blogId
      blog.addComment(this.commentinfo)
      .then(response => {
          this.$message({
          message: '评论成功',
          type: 'success'
        });

         this.getCommentlist()
         this.commentinfo.commentContent=''
      })
     
    },
    getCommentInfo(id){
        blog.getCommentInfo(id)
        .then(response => {
          this.commentsupportinfo = response.data.data.comments
        })
    },
    deletecomment(id){
       this.$confirm('确定删除此评论？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
         blog.deleteComment(id)
        .then(response => {
         this.getCommentlist()
      })
          this.$message({
            type: 'success',
            message: '删除成功!'
          });
        }).catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          });          
        });

    },
    }
};
</script>
<style>
.changeStyle{
  color: #0099cc;
}
.changeStyle2{
  color: #0099cc;
} 
.com2{
  display:none
}  
.commentStyle {
  display:block;
}


  .authorinfo{
    position: relative;
    text-align: center;
    padding-bottom:20px;
    background-color:#fff;
    border-radius: 10px;
    opacity: 0.9;
  }
  .authorinfo:hover{
    opacity:1;
  }
  .authorinfo .background {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    height: 125px;
    z-index: 1;
    border-radius: 10px;

  }
  .authorinfo .avatar {
    position: relative;
    margin: 75px auto 15px;
    width: 100px;
    height: 100px;
    border: 5px solid gray;
    border-radius: 50%;
    z-index: 9;
  }
  .authorinfo  .name {
    font-size: 18px;
    color: black;
    line-height: 30px;
    font-weight: 700;
  }
  .authorinfo .email{
    font-size: 14px;
    color: black;
  }
  .authorinfo .line {
    height: 1px;
    background-color:black;
    margin: 10px 20px;
  }
  .authorcount{
    margin-left:-30px
  }
  .authorcount li{
    width:60px;
    display: inline-block;
  }
  .textt{
    width:100%;
    position: relative;
    background-color:#fff;
    height:auto;
    overflow: hidden;
    box-shadow: 0 2px 4px 0 rgba(0,0,0,.05);
    padding-left:27px;
    padding-right:30px;
    padding-top:10px;
  }

  .texttitle{
    font-size: 32px;
    color: #222226;
    font-weight: 600;
  }
  .textinfoo {
    width:100%;
    height:100%;  
    background-color: #f8f8f8;
    margin-left:10px;
  }
 
  .textinfoo p{
    display:inline-block;
    color:gray;
    padding-left:30px;
    font-size: 15px;
    padding-top:10px
  }
  .textinfoo p:first-child{
    color:black
  }
  .textinfoo img{
    width: 46px;
    height: 42px;
  }
  .textcontent{
    margin-top:40px;
  }

  .operation{
    width:110%;
    height:50px;
    background-color:#f8f8f8;
    margin-top:50px;
    margin-left:-26px;
    padding-left:200px;
  }
  .commentlist{
     width: 100%;
     display:inline-block;
     height: 60px;
     border-bottom: 1px gainsboro solid;
     padding-top: 10px;
     position: relative;
  }
  .commentlist img{
    display: block;
  }
  .commentlist p{
     margin-top:5px;
     font-size:16px;
     float:left;
  }
  .commentname{
    margin-left:10px;
  }
  .operation p{
    display:inline-block;
    line-height: 50px;
    font-size: 16px;
    margin-left:40px;
    cursor:pointer;
  }
  .comment{
    margin-top:10px;
    width:100%;
    position: relative;
    background-color:#fff;
    height:auto;
    overflow: hidden;
    box-shadow: 0 2px 4px 0 rgba(0,0,0,.05);
    padding-left:27px;
    padding-right:30px;
    padding-top:20px;
    margin-bottom: 20px;
    padding-bottom: 50px;
  }
  .tbutton{
    position: absolute;
    right:0;
    bottom:26px;
  }
  .comment img {
    float:left;
  }
  .recommenddd{
    margin-top:20px;
    position: relative;
    background-color:#fff;
    border-radius: 10px;
    opacity: 0.9;
    height:380px;
    overflow: hidden;
    margin-bottom:10px ;
  }
  .recommenddd:hover{
    opacity: 1.0;
  }
  .recommenddd hr{
      background-color: rgb(250,206,224);
      width: 350px;
      height:0.5px;
      position:absolute;
      top:25px;
      
  }
  .recommenddd span{
      display:inner-block;
      position: absolute;
      font-size: 20px;
      left: 20px;
      top: 10px;
      font-weight: bold;
   
  }
  ul{
    list-style: none;
  }
  .recommenddd .content{
    background-color:#fff;
    position: absolute;
    width: 100%;
    top:47px;
    overflow: hidden;
  }


  .contenttt li{
      position: relative;
      width: 100%;
      height: 90px;
      top:50px;
      margin-top:10px;
     
  }
  .contenttt li img{
    position: absolute;
    width: 100px;
    height: 75px;
    left:-10px;

    border-radius: 5px;
   
  }
  .contenttt li .text{
    width: 100px;
    position: absolute;
    left: 95px;
    font-size:20px;
  }
  .contenttt li hr{
    background-color: rgb(250,206,224);
    height: 0.5px;
    border:0px;
    top:60px;
    left:-20px
  }
  .contenttt li .info{
    position: absolute;
    left:95px;
    top:55px
  }
  .contenttt b{
      font-size: 10px;
      padding: 2px;
      cursor: pointer;
      color:gray;
  }
  .contenttt .info .shijian{
      font-size: 12px;
  }
</style>